package org.zjx.command.basic;

import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import lombok.extern.slf4j.Slf4j;
import org.zjx.command.Command;
import org.zjx.command.CommandFactory;
import org.zjx.core.IWindow;
import org.zjx.state.StateManager;

@Slf4j
public class GameDragCommand extends Command {
    private final int startX, startY, endX, endY;

    public GameDragCommand(IWindow window, StateManager stateManager, int startX, int startY, int endX, int endY) {
        super(window, false,stateManager);
        this.startX = startX;
        this.startY = startY;
        this.endX = endX;
        this.endY = endY;
    }

    @Override
    protected void doExecute() throws Exception {
        GameMoveCommand gameMoveCommand = new GameMoveCommand(targetWindow,stateManager,startX,startY,2);
        gameMoveCommand.execute();
        User32.INSTANCE.SendMessage(getTargetWindow().getHwnd(),0x0201, new WinDef.WPARAM(0), null);
        CommandFactory.waitDirectly(targetWindow, 10);
        gameMoveCommand = new GameMoveCommand(targetWindow,stateManager,endX,endY,2);
        gameMoveCommand.execute();
        User32.INSTANCE.SendMessage(getTargetWindow().getHwnd(),  0x0202, new WinDef.WPARAM(0), null);

    }
}